
const express= require('express');
const app = express();
const path = require('path');



app.get('/user',(request,response)=>{
    // 解构赋值
 const{userId} = request.query;

    if(userId !== '001'){
        return response.send(
            {
                code : 10001,
                msg:'查询失败',
                data: null
            }
        )
    }
    response.send({
        code:10000,
        msg:'查询成功',
        data:{
            name: '小a',
            age: 18,
            sex: '女'

        }
      
        
    })
    app.get('/userInfo/:userId',(request,response)=>{
        const {userId} = request.params;
    })
    if(userId !== '001'){
        return response.send(
            {
                code : 10001,
                msg:'查询失败',
                data: null
            }
        )
    }
    response.send({
        code:10000,
        msg:'查询成功',
        data:{
            name: '小a',
            age: 18,
            sex: '女'

        }
      
        
    })

})

  
    // 静态资源部署接口
    app.get('/1',(request,response)=>{
        const filePath= path.resolve(__dirname,'./01.基础的get请求.html')
        response.sendFile(filePath)
    })
    app.get('/2',(request,response)=>{
        const filePath= path.resolve(__dirname,'./02.get练习.html')
        response.sendFile(filePath)
    })
    app.get('/3',(request,response)=>{
        const filePath= path.resolve(__dirname,'./03.get练习.html')
        response.sendFile(filePath)
    })

app.listen(5050,()=>{
console.log('running 请访问 http://127.0.0.1:5050/1');
})